#!/bin/bash

randomNum() {
	if [ $# -eq 1 ];then
		(( rand = $RANDOM*$1/32767 ))
		echo $rand
	else
		echo $RANDOM
	fi
}

completar() {
	formedNumber=""
	if [ $# -eq 2 ];then
		(( max = $2 - 1 ))

		for (( i = $max; i >= 0; i-- ))
		do
			((tenth = 10 ** $i))
			if [ $1 -lt $tenth ];then
				formedNumber=$formedNumber"0"
			else
				formedNumber=$formedNumber"$1"
				break;
			fi
		done
		echo $formedNumber
	else
		echo "maaaaaaaal"
	fi
}

genRegistro() {

	codCentral=CENTRAL
	ports=
	ADSL=N
	DISP20=N
	DISP50=N
	DISP100=N

	
	#var=`randomNum 999`
	var=`completar $1 3`
	codCentral=$codCentral$var


	var=`randomNum 9999999999`
	var=`completar $var 10`
	ports=$var

	var=`randomNum 2`
	if [ $var -eq 1 ];then
		ADSL=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		DISP20=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		DISP50=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		DISP100=S
	fi


	registro=$codCentral","$ports","$ADSL","$DISP20","$DISP50","$DISP100
	echo $registro
}


for (( i = 1 ; i < 51 ; i++ ))
do
	registro=`genRegistro $i`
	echo $registro
done

